package com.educate.serviceedu.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.educate.commonutils.ResultOne;
import com.educate.serviceedu.entity.EduCourse;
import com.educate.serviceedu.entity.EduTeacher;
import com.educate.serviceedu.service.EduCourseService;
import com.educate.serviceedu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;
    //查询前8条热门课程,查询前4名讲师
    @GetMapping("index")
    public ResultOne index(){
        //查询前8条热门课程
        QueryWrapper<EduCourse> queryWrapper=new QueryWrapper();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 8");
        List<EduCourse> eduList = eduCourseService.list(queryWrapper);
        //查询前4名名师
        QueryWrapper<EduTeacher> queryWrapper1=new QueryWrapper<>();
        queryWrapper1.orderByDesc("id");
        queryWrapper1.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(queryWrapper1);
        return ResultOne.ok().data("eduList",eduList).data("teacherList",teacherList);
    }
}
